/**
 * 公共配置管理
 * 文件命名格式：zmn.模块名称.表名称.功能.js
 * @author hedaiping
 * @since 2019/3/25
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var table = layui.table;
    var laypage = layui.laypage;

    var cols = [
        [
            {field: 'mapId', type: 'checkbox', fixed: 'left', width: 50, align: 'center'},
            {field: 'mapId', title: '码表ID',fixed: 'left', width: 175, align: 'center', unresize: true, sort: false},
            {field: 'name', title: '配置名称',fixed: 'left', width: 175, align: 'center', unresize: true, sort: false},
            {field: 'plat', title: '平台', width: 175, align: 'center', unresize: true, templet: function (d) {
                    return zmnEnum.PLAT_TYPE[d.plat];
                }
            },
            {field: 'oneTypeId', title: '一级类别Id', width: 175, align: 'center', unresize: true, sort: false},
            {field: 'twoTypeId', title: '二级类别Id', width: 175, align: 'center', unresize: true, sort: false},
            {field: 'threeTypeId', title: '三级类别Id', width: 175, align: 'center', unresize: true, sort: false, templet:d=>{
                if (d.threeTypeId) {
                    return d.threeTypeId;
                } else {
                    return "--";
                }
                }},
            {field: 'status', title: '状态', width: 175, align: 'center', unresize: true, templet: function (d) {
                return zmnEnum.STATUS[d.status];
            }
        },
            {field: 'creater', title: '创建人', width: 175, align: 'center', unresize: true, templet:d=>{
                    if (d.creater) {
                        return d.creater;
                    } else {
                        return "--";
                    }
                }},
            {field: 'createTime', title: '创建时间', templet: '#createTime', width: 175, align: 'center', unresize: true,
                templet :function (t){
                    if (t.createTime) {
                        return zmnUtil.createTime(t.createTime);
                    } else {
                        return "--";
                    }

                }
            }, {field: 'updater', title: '编辑人', width: 150, align: 'center', unresize: true, templet:d=>{
                if (d.updater) {
                    return d.updater;
                } else {
                    return "--";
                }
            }},
            {field: 'updateTime', title: '编辑时间', templet: '#updateTime', width: 175, align: 'center', unresize: true,
                templet :function (t){
                    if (t.updateTime) {
                        return zmnUtil.createTime(t.updateTime);
                    } else {
                        return "--";
                    }
            }}, {
            fixed: 'right', title: '操作', width: 175, align: 'center', templet:
            '<div>' +
            (json.hasEdit ? '<a lay-href="/funswitch/detail.action?mapId={{d.mapId}}" class="layui-btn layui-btn-xs"><i class="layui-icon">&#xe642;</i>编辑</a>' : '') +
            '</div>'
        }
        ]
    ];
    table.render({
        elem: "#zmn-basecodemap-table",
        toolbar: "#zmn-basecodemap-table-tool",
        title: "公共配置列表",
        data: json.items,
        limit: json.pageSize,
        cols: cols,
        page: true,
        height: 'full-120'
    });

    laypage.render(zmnPage.laypageOptions(json));

    var ids = new Array();

    // 选择（全选或单选）
    table.on("checkbox(zmn-basecodemap-table)", function () {
        ids = zmnPage.layIdsChecked(json.items, "mapId");
    });

    // 启用/停用
    table.on("toolbar(zmn-basecodemap-table)", function (obj) {
        if (obj.event != "start" && obj.event != "stop") {
            return;
        }
        if (ids.length === 0) {
            return layer.alert("请选择至少一个配置！");
        }
        zmnPage.layStartStop(obj, "/funswitch/updateStatus.action", ids.join(","));
    });

    //对外暴露的接口
    exports('art_funswitch_list', {});
});